package com.cykj.pos.controller.api;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cykj.common.annotation.Log;
import com.cykj.common.core.controller.BaseController;
import com.cykj.common.core.domain.AjaxResult;
import com.cykj.common.enums.BusinessType;
import com.cykj.pos.domain.AizWithdrawalProfit;
import com.cykj.pos.service.IAizWithdrawalProfitService;
import com.cykj.common.utils.poi.ExcelUtil;
import com.cykj.common.core.page.TableDataInfo;

/**
 * 提现分润Controller
 *
 * @author weijianbo
 * @date 2025-02-17
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/pos/profit" )
public class AizWithdrawalProfitController extends BaseController {

    private final IAizWithdrawalProfitService iAizWithdrawalProfitService;

    /**
     * 查询提现分润列表
     */
    @PreAuthorize("@ss.hasPermi('pos:profit:list')")
    @GetMapping("/list")
    public TableDataInfo list(AizWithdrawalProfit aizWithdrawalProfit) {
        startPage();
        List<AizWithdrawalProfit> list = iAizWithdrawalProfitService.queryList(aizWithdrawalProfit);
        return getDataTable(list);
    }

    /**
     * 导出提现分润列表
     */
    @PreAuthorize("@ss.hasPermi('pos:profit:export')" )
    @Log(title = "提现分润" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(AizWithdrawalProfit aizWithdrawalProfit) {
        List<AizWithdrawalProfit> list = iAizWithdrawalProfitService.queryList(aizWithdrawalProfit);
        ExcelUtil<AizWithdrawalProfit> util = new ExcelUtil<AizWithdrawalProfit>(AizWithdrawalProfit.class);
        return util.exportExcel(list, "profit" );
    }

    /**
     * 获取提现分润详细信息
     */
    @PreAuthorize("@ss.hasPermi('pos:profit:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iAizWithdrawalProfitService.getById(id));
    }

    /**
     * 新增提现分润
     */
    @PreAuthorize("@ss.hasPermi('pos:profit:add')" )
    @Log(title = "提现分润" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AizWithdrawalProfit aizWithdrawalProfit) {
        return toAjax(iAizWithdrawalProfitService.save(aizWithdrawalProfit) ? 1 : 0);
    }

    /**
     * 修改提现分润
     */
    @PreAuthorize("@ss.hasPermi('pos:profit:edit')" )
    @Log(title = "提现分润" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AizWithdrawalProfit aizWithdrawalProfit) {
        return toAjax(iAizWithdrawalProfitService.updateById(aizWithdrawalProfit) ? 1 : 0);
    }

    /**
     * 删除提现分润
     */
    @PreAuthorize("@ss.hasPermi('pos:profit:remove')" )
    @Log(title = "提现分润" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iAizWithdrawalProfitService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }


//    // app 提现分润记录
//    @PostMapping("/app/back/withdrawal/profit/records")
//    public AjaxResult appBackWithdrawalProfitRecords(@RequestBody AizWithdrawalProfit aizWithdrawalProfit){
//        return iAizWithdrawalProfitService.appBackWithdrawalProfitRecords(aizWithdrawalProfit);
//    }

}
